function init(param, data, slot)
{
	Packages.system.Platform.renderPortlet(slot);
	displaySurveyResultList();
	fillUserList();
}

function displayItemPortlet(cont:String)
{
	mlf.gatekeeper.native.Caller.MLoader(null, null, null, null, cont);
}

function displaySurveyResultList()
{
	var dp:Array=Packages.modula.SurveyItem.getDataProvider();
	for (var i=1; i<dp.length; i++)
	{
		displayItemPortlet(Packages.modula.SurveyItem.getSurveyResultItem(dp[i]));
	}
}

function clearItems()
{
	//trace("clearItems");
	var dp:Array=Packages.modula.SurveyItem.getDataProvider();
	for (var i=0; i<dp.length; i++)
	{
		var item=mlf.gatekeeper.native.Caller.scanElement("SurveyResult", "item_"+i);
		if (item!=null) 
		{
			item.unloadMovie();
			item.removeMovieClip();	
			mlf.mcmanager.component.IndexSlot.removeElement("SurveyResult", "item_"+i); 
		}
	}
}

function fillUserList()
{
	var item=new Object();
	item.type="getSurveyRespondents";
	item.param=new Object();
	item.result=new Object();
	item.result.owner=this;
	item.result.onResult=function(res)
	{
		trace("getSurveyRespondents.onResult.obj.returnObj: "+res.returnObj);
		if (res.returnObj!=null)
		{
			var userList=mlf.gatekeeper.native.Caller.scanElement("SurveyResult", "userList"); 
			userList.htmlText=res.returnObj;
		}
	}	
	Packages.system.MLF.rtmpCaller(item);	
}

function queryItem(param, data, slot)
{
	//trace("queryItem...");
	var id:String=param.substring(param.indexOf("query_")+6);
	var obj:Object=Packages.modula.SurveyItem.getSurveyItemObject(id);
	for (var a in obj.answer)
	{
		var item=new Object();
		item.type="getSurveyCount";
		item.param=new Object();
		item.param.name=id;
		item.param.value=a;
		item.result=new Object();
		item.result.owner=this;
		//for (var b in item.param) trace("item.param."+b+":"+item.param[b]);
		item.result.onResult=function(res)
		{
			trace("getSurveyRespondents.onResult.obj.returnObj: "+res.returnObj);
			if (res.returnObj!=null)
			{
				var split:Array=res.returnObj.split("=");
				var count=mlf.gatekeeper.native.Caller.scanElement("SurveyResult", "count_"+id+"_"+split[0]); 
				count.htmlText=split[1];
			}
		}	
		Packages.system.MLF.rtmpCaller(item);		
	}
}

function query(param, data, slot)
{
	if (data.uuid==""||data.uuid==null)	return;
	var item=new Object();
	item.type="getSurveyByUuid";
	item.param=new Object();
	item.param.uuid=data.uuid;
	item.result=new Object();
	item.result.owner=this;
	//for (var b in item.param) trace("item.param."+b+":"+item.param[b]);
	item.result.onResult=function(res)
	{
		trace("getSurveyByUuid.onResult.obj.returnObj.length: "+res.returnObj.length);
		if (res.returnObj!=null)
		{
			Packages.modula.SurveyItem.setDataProvider(null);
			Packages.modula.SurveyItem.initDataProvider();
			for (var a in res.returnObj)
			{
				var survey:Object=res.returnObj[a];
				if (survey.surveyName=="name") {
					var nameInput=mlf.gatekeeper.native.Caller.scanElement(slot, "nameInput");
					nameInput.htmlText=survey.surveyValue;
				} else if (survey.surveyName=="mail") {
					var mailInput=mlf.gatekeeper.native.Caller.scanElement(slot, "mailInput");
					mailInput.htmlText=survey.surveyValue;				
				} else if (survey.surveyName=="mobile") {
					var mobileInput=mlf.gatekeeper.native.Caller.scanElement(slot, "mobileInput");
					mobileInput.htmlText=survey.surveyValue;								
				} else if (survey.surveyName=="comment") {
					var commentInput=mlf.gatekeeper.native.Caller.scanElement(slot, "commentInput");
					commentInput.htmlText=survey.surveyValue;												
				} else {
					Packages.modula.SurveyItem.updateSurveyItemObject(survey.surveyName, survey.surveyValue);
				}
			}	
			this.owner.clearItems();
			this.owner.displaySurveyResultList();
		}
	}	
	Packages.system.MLF.rtmpCaller(item);	
	var uuidInput=mlf.gatekeeper.native.Caller.scanElement(slot, "uuidInput");
	uuidInput.htmlText="";
}

function rolloverButton(param, data, slot)
{
	//trace("rolloverButton...param:"+param);
	mlf.mcmanager.PathResolver.extractPath(param+"Bg")._visible=false;
	Packages.system.Platform.highlightBG(mlf.mcmanager.PathResolver.extractPath(param), mlf.gatekeeper.native.Caller.scanElement(slot, "highlightBg"), 50);	
}

function rolloutButton(param, data, slot)
{
	mlf.mcmanager.PathResolver.extractPath(param+"Bg")._visible=true;
	Packages.system.Platform.highlightBG(mlf.mcmanager.PathResolver.extractPath(param), mlf.gatekeeper.native.Caller.scanElement(slot, "highlightBg"), 0);	
}

function quit(param, data, slot)
{
	mlf.mcmanager.SMCManager.popInstance(slot);
}
